/**
 * Copyright 2010 Victor Egea Hernando
 *
 * RockScript is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 * 
 * RockScript is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with RockScript.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <fstream>
#include <iostream>

#include <ctime>
#include <cstdlib>
#include <corelib/corelib.h>

// type: vector of ustrings
typedef std::vector<corelib::ustring> usvec;
// vector of ustrings
usvec lines;
// char buffer
char buffer[4096];

// unary test for checking corelib::ustring functionality
int main( int argc, char *argv [] )
{
    // open "utf8-demo.txt"
    std::fstream input( "utf8-demo.txt", std::ios_base::in );
    std::fstream output( "../../../utf8-output.txt", std::ios_base::out );

    // check file state
    CORELIB_ASSERT( input.is_open() && output.is_open() );

    // write what are we going to do
    std::cout << "reading utf8 strings from utf8-demo.txt & "; 
    std::cout << "writing them to ../../../utf8-output.txt" << std::endl;

    // store unicode strings
    while( !input.eof() ){
        // get line
        input.getline( buffer, 4096 );
	// create unicode string
	corelib::ustring ustr( buffer );
	// this string is above_bmp
	if( ustr.above_bmp() ){
	    std::cout << "above_bmp: " << ustr << std::endl;
        }
        // add line to vector
	lines.push_back( ustr );
    }

    // save unicode strings
    for(usvec::iterator it=lines.begin();it!=lines.end();++it){
        output << *it << std::endl;
    }

    // close streams
    input.close(); output.close();

    std::cout << "printing string operations: " << std::endl;
    // create special unicode string above BMP
    corelib::ustring test( "Go to the Hell!Hello World!" );
    // print string operations
    std::cout << "(\"" << test << "\").substr(15): \"" << test.substr(15) << "\"" << std::endl;
    // print string operations
    std::cout << "change order: \"" << test.substr(15) + " <> " + test.substr(0,14) << "\"" << std::endl;

    return 0;
}

